package com.example.myapplication.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.myapplication.Data.SignInList;
import com.example.myapplication.R;
import com.example.myapplication.Tool.TimestampTool;

import java.util.List;

public class SignInListAdapter extends ArrayAdapter<SignInList> {
    private List<SignInList> mSignInList;
    private Context mContext;
    private int resourceId;

    public SignInListAdapter(Context context,
                             int resourceId, List<SignInList> data) {
        super(context, resourceId, data);
        this.mContext = context;
        this.mSignInList = data;
        this.resourceId = resourceId;
    }

    @Override
    public View getView(int position,
                        View convertView, ViewGroup parent) {
        SignInList signInList = getItem(position);

        View view ;

        final ViewHolder vh;

        if (convertView == null) {
            view = LayoutInflater.from(getContext())
                    .inflate(resourceId, parent, false);

            vh = new ViewHolder();
            vh.tvUserSignId = view.findViewById(R.id.tv_user_sign_id);
            vh.tvCourseAddr = view.findViewById(R.id.tv_course_addr);
            vh.tvCreateTime = view.findViewById(R.id.tv_create_time);

            view.setTag(vh);
        } else {
            view = convertView;
            vh = (ViewHolder) view.getTag();
        }
        Log.d("Total", String.valueOf(signInList.getUserSignId()));
        //显示文字
        vh.tvUserSignId.setText(signInList.getUserSignId());
        vh.tvCourseAddr.setText(signInList.getCourseAddr());
        String timestamp = TimestampTool.timestampToDateTime(signInList.getCreateTime());
        vh.tvCreateTime.setText(timestamp);
        return view;
    }

    class ViewHolder {
        TextView tvUserSignId;
        TextView tvCourseAddr;
        TextView tvCreateTime;

    }
}
